package com.ccgk.logistics.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ccgk.common.page.PaginationVo;
import com.ccgk.logistics.domain.ContainerExample;
import com.ccgk.logistics.domain.Country;
import com.ccgk.logistics.domain.CountryExample;
import com.ccgk.logistics.persistence.CountryMapper;
import com.ccgk.logistics.service.CountryService;
@Service
public class CountryServiceImpl implements CountryService{
	
	@Autowired
	private CountryMapper countryMapper;
	
	@Override
	public Integer add(Country country) {
		return countryMapper.insert(country);
	}

	@Override
	public Integer delete(int id) {
		return countryMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Country> findAll() {
		return countryMapper.selectByExample(null);
	}

	@Override
	public Country getById(int id) {
		return countryMapper.selectByPrimaryKey(id);
	}

	@Override
	public Integer update(Country country) {
		return countryMapper.updateByPrimaryKey(country);
	}

	@Override
	public void batchDelete(Integer[] idIntArray) {
		for(Integer id:idIntArray){
			delete(id);
		}
	}

	@Override
	public PaginationVo<Country> findList(ContainerCriteria criteria,
			int currentPage, int pageSize) {
		CountryExample example = new CountryExample();
		CountryExample.Criteria _criteria = example.createCriteria();
		Map<Integer,Object> params = criteria.getParams();
		for(Integer key : params.keySet()){
			if(key.equals(1)){
				_criteria.andNameLike(params.get(key).toString());
			}
		}
		List<Country> data = countryMapper.selectByExample(example,new RowBounds((currentPage-1)*pageSize, pageSize));
		int recordCount = countryMapper.countByExample(example);
		PaginationVo<Country> result = new PaginationVo<Country>(data, recordCount, pageSize, currentPage);
		return result;
	}

}
